package com.zb.code.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.Result;
import com.zb.service.ZjCodeFieldService;
import com.zb.utils.TokenUtil;
import com.zb.vo.CodeFieldSelectVo;
import com.zb.vo.CodeFieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 编码字段表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-23
 */
@Api(tags = "编码设置字段类")
@RestController
@RequestMapping("/codeSet/Field")
public class ZjCodeFieldController {
    @Resource
    private ZjCodeFieldService codeFieldService;

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "编码档案-编码设置 - 编码字段 - 新增或修改编码字段")
    @ApiOperation("新增或修改编码字段")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid CodeFieldVo codeFieldVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        codeFieldService.save(custAccId, codeFieldVo);
        return Result.success(null == codeFieldVo.getId()? "新增编码字段成功" : "修改编码字段成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.SELECT, remark = "编码档案-编码设置 - 编码字段 - 获取编码字段列表")
    @ApiOperation("获取编码字段列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody @Valid CodeFieldSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取编码字段列表成功").data(codeFieldService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.SELECT, remark = "编码档案-编码设置 - 编码字段 - 获取编码字段详情")
    @ApiOperation("根据ID获取编码字段详情")
    @GetMapping("/getInfo/{id}")
    public Result getInfo(@PathVariable @ApiParam(value = "编码字段ID", required = true) Long id) {
        return Result.success("获取编码字段详情成功").data("row", codeFieldService.getInfo(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码设置 - 编码字段 - 批量更改是否移动端显示选项")
    @ApiOperation("批量更改是否移动端显示选项")
    @PutMapping("/mobileShow")
    public Result mobileShow(@RequestParam @ApiParam(value = "是否移动端显示：false-不显示，true-显示", required = true, example = "false") boolean mobileShow,
                             @RequestBody @ApiParam(value = "编码字段ID集合", required = true) List<Long> idList) {
        codeFieldService.updateMobileShowBatchByIds(idList, mobileShow);
        return Result.success("更改移动端显示选项成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码设置 - 编码字段 - 批量更改是否列表显示选项")
    @ApiOperation("批量更改是否列表显示选项")
    @PutMapping("/listShow")
    public Result listShow(@RequestParam @ApiParam(value = "是否列表显示：false-不显示，true-显示", required = true, example = "false") boolean listShow,
                             @RequestBody @ApiParam(value = "编码字段ID集合", required = true) List<Long> idList) {
        codeFieldService.updateListShowBatchByIds(idList, listShow);
        return Result.success("更改列表显示选项成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码设置 - 编码字段 - 批量更改是否列表显示选项")
    @ApiOperation("批量更改列表显示查询条件选项")
    @PutMapping("/listCondition")
    public Result listCondition(@RequestParam @ApiParam(value = "是否列表显示查询条件：false-不显示，true-显示", required = true, example = "false") boolean listCondition,
                           @RequestBody @ApiParam(value = "编码字段ID集合", required = true) List<Long> idList) {
        codeFieldService.updateListConditionBatchByIds(idList, listCondition);
        return Result.success("更改列表显示查询条件选项成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码设置 - 编码字段 - 批量更改编码字段状态")
    @ApiOperation("批量更改编码字段状态")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "编码字段状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                                @RequestBody @ApiParam(value = "编码字段ID集合", required = true) List<Long> idList) {
        codeFieldService.updateDisabledBatchByIds(idList, status);
        return Result.success(status? "字段禁用成功" : "字段启用成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码设置 - 编码字段 - 批量删除编码字段")
    @ApiOperation("批量删除编码字段")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "编码字段ID集合", required = true) List<Long> idList) {
        codeFieldService.deleteBatchByIds(idList);
        return Result.success("删除字段成功");
    }

}
